
$(function() {
	
	$(function() {
		var data = window.sessionStorage.getItem('myData');
	    if (!data) {
	        window.location = 'login.html';
	    } else {
	    	data = JSON.parse(data);
	    	console.log(data);
		    $('.button').click(function(){
		    	className = this.id;
		    	var url = 'http://ittalentsapi.bashibozuk.eu/game/game-start?user_id='+data.id+'&X-GameID=102';
		    	$.ajax(url, {
					method: 'GET',
					crossDomain : true,
					success: function(data) {
						console.log(data);
						console.log(data.id);
						var game = new Game(data.id,className);
						game.load();
					}
				});	
		    });
	    }
	});
	var url = 'http://ittalentsapi.bashibozuk.eu/game/game-end?id='+this.id2+'&X-GameID=102&score='+this.playerPoint;
	if(!this.responseFinished) {
		console.log(this.id2);
		$.ajax(url, {
			method: 'GET',
			crossDomain : true,
			success: function(data) {
				console.log(data);
			}
		});
		this.responseFinished = true;
	}
	
	
})